#include "ip_packet.h"

// 计算校验和函数
unsigned short calculateChecksum(unsigned short* addr, int len) {
    unsigned long sum = 0;
    while (len > 1) {
        sum += *addr++;
        len -= 2;
    }
    if (len) {
        sum += *(unsigned char*)addr;
    }
    while (sum >> 16) {
        sum = (sum & 0xFFFF) + (sum >> 16);
    }
    return ~sum;
}
